package data.processor;

import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Comparator;
import java.util.List;

import comparetor.CustomerComparetorByBirth;
import comparetor.CustomerComparetorById;
import pojo.Customer;
import processor.DataProcessor;
import processor.impl.DataProcessorImpl;
import result.show.ResultShow;
import scanner.DataScanner;
import scanner.impl.DataScannerImpl;

public class DataHandle {
	private String[] command;
	
	public DataHandle(String[] command){
		this.command=command;
		
	}
	public String dataprocessor() throws Exception{
		switch (command[0]) {
		case "L":
			if (command[1].equals("xml")) {
				Comparator<Customer> comparator=new CustomerComparetorById();
				DataScanner scanner=new DataScannerImpl(new FileInputStream("data.txt"));
				List<Customer> list=scanner.scann();
				DataProcessorImpl dp=new DataProcessorImpl(list, "xml");
				return dp.process(comparator).toString();
			}else {
				Comparator<Customer> comparator=new CustomerComparetorByBirth();
				DataScanner scanner=new DataScannerImpl(new FileInputStream("data.txt"));
				List<Customer> list=scanner.scann();
				DataProcessorImpl dp=new DataProcessorImpl(list, "line");
				return dp.process(comparator).toString();
			}
		case "C":
			Comparator<Customer> comparator=new CustomerComparetorById();
			DataScanner scanner=new DataScannerImpl(new FileInputStream("data.txt"));
			List<Customer> list=scanner.scann();
			DataProcessorImpl dp=new DataProcessorImpl(list, "xml");
			String string=dp.process(comparator).toString();
			OutputStream out=new FileOutputStream("data1.txt");
			DataOutputStream dout=new DataOutputStream(out);
			dout.writeChars(string);
			return "Success Handle";
		default:
			return null;
		}
		
	}

}
